@file:Suppress("unused", "NOTHING_TO_INLINE", "FunctionName")

package top.techqi.core.kext

/* ========== ========== ========== ========== ========== ========== ==========
 * ========== ========== ========== = concat = ========== ========== ==========
 * ========== ========== ========== ========== ========== ========== ========== */

/* ---------- ---------- Single Word ---------- ---------- */

inline fun WORD_T(hByte: Byte, lByte: Byte): Short {
    return WORD(hByte.toInt(), lByte.toInt()).toShort()
}

/* ---------- ---------- Double Word ---------- ---------- */

inline fun DWORD_T(hWord: Short, lWord: Short): Int {
    return DWORD(hWord.toInt(), lWord.toInt())
}

inline fun DWORD_T(hhByte: Byte, hlByte: Byte, lhByte: Byte, llByte: Byte): Int {
    return DWORD(hhByte.toInt(), hlByte.toInt(), lhByte.toInt(), llByte.toInt())
}

/* ---------- ---------- Quadra Word ---------- ---------- */

inline fun QWORD_T(hhWord: Short, hlWord: Short, lhWord: Short, llWord: Short): Long {
    return QWORD(hhWord.toInt(), hlWord.toInt(), lhWord.toInt(), llWord.toInt())
}

inline fun QWORD_T(
    hhhByte: Byte, hhlByte: Byte, hlhByte: Byte, hllByte: Byte,
    lhhByte: Byte, lhlByte: Byte, llhByte: Byte, lllByte: Byte
): Long {
    return QWORD(
        hhhByte.toInt(), hhlByte.toInt(), hlhByte.toInt(), hllByte.toInt(),
        lhhByte.toInt(), lhlByte.toInt(), llhByte.toInt(), lllByte.toInt()
    )
}

/* ========== ========== ========== ========== ========== ========== ==========
 * ========== ========== ========== = divide = ========== ========== ==========
 * ========== ========== ========== ========== ========== ========== ========== */

/* ---------- ---------- Single Word ---------- ---------- */

inline val Short.hByte_T: Byte
    get() = ((this.toInt() shr 8) and 0xFF).toByte()

inline val Short.lByte_T: Byte
    get() = ((this.toInt() shr 0) and 0xFF).toByte()

/* ---------- ---------- Double Word ---------- ---------- */

inline val Int.hWord_T: Short
    get() = ((this shr 16) and 0xFFFF).toShort()

inline val Int.lWord_T: Short
    get() = ((this shr 0) and 0xFFFF).toShort()

inline val Int.hhByte_T: Byte
    get() = ((this shr 24) and 0xFF).toByte()

inline val Int.hlByte_T: Byte
    get() = ((this shr 16) and 0xFF).toByte()

inline val Int.lhByte_T: Byte
    get() = ((this shr 8) and 0xFF).toByte()

inline val Int.llByte_T: Byte
    get() = ((this shr 0) and 0xFF).toByte()

/* ---------- ---------- Quadra Word ---------- ---------- */

inline val Long.hhWord_T: Short
    get() = ((this shr 48) and 0xFFFF).toShort()

inline val Long.hlWord_T: Short
    get() = ((this shr 32) and 0xFFFF).toShort()

inline val Long.lhWord_T: Short
    get() = ((this shr 16) and 0xFFFF).toShort()

inline val Long.llWord_T: Short
    get() = ((this shr 0) and 0xFFFF).toShort()

inline val Long.hhhByte_T: Byte
    get() = ((this shr 56) and 0xFF).toByte()

inline val Long.hhlByte_T: Byte
    get() = ((this shr 48) and 0xFF).toByte()

inline val Long.hlhByte_T: Byte
    get() = ((this shr 40) and 0xFF).toByte()

inline val Long.hllByte_T: Byte
    get() = ((this shr 32) and 0xFF).toByte()

inline val Long.lhhByte_T: Byte
    get() = ((this shr 24) and 0xFF).toByte()

inline val Long.lhlByte_T: Byte
    get() = ((this shr 16) and 0xFF).toByte()

inline val Long.llhByte_T: Byte
    get() = ((this shr 8) and 0xFF).toByte()

inline val Long.lllByte_T: Byte
    get() = ((this shr 0) and 0xFF).toByte()
